home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / game / shoot / ADoom_src_1_1.lha / ADoom_src / amiga_fixed.s < prev    next >
Text File  |  1998-01-25  |  3KB  |  168 lines

  1.         mc68020
  2.         mc68881
  3.         multipass
  4.     if (_eval(DEBUG)&$8000)
  5.         debug    on,lattice4
  6.     endc
  7.  
  8. ;-----------------------------------------------------------------------
  9.         xdef    _FixedMul
  10.         xdef    @FixedMul_040
  11.         xdef    @FixedMul_060fpu
  12.         xdef    @FixedMul_060
  13.         xdef    _FixedDiv
  14.         xdef    @FixedDiv_040
  15.         xdef    @FixedDiv_060fpu
  16.         xdef    @SetFPMode
  17.  
  18. ;-----------------------------------------------------------------------
  19. ; set 68060 FPU rounding mode to "truncate towards minus infinity"
  20. ; otherwise demos get out of step and play wrong
  21.  
  22.         cnop    0,4
  23.  
  24. @SetFPMode    fmove.l    fpcr,d0
  25.         or.b    #$20,d0
  26.         and.b    #~$10,d0
  27.         fmove.l    d0,fpcr
  28.         rts
  29.  
  30. ;-----------------------------------------------------------------------
  31.         cnop    0,4
  32.  
  33. ; fixed_t FixedMul (fixed_t a, fixed_t b)
  34.  
  35. @FixedMul_040    muls.l    d1,d1:d0
  36.         move.w    d1,d0
  37.         swap    d0
  38.         rts
  39.  
  40. ;-----------------------------------------------------------------------
  41.         cnop    0,4
  42.  
  43. ; special version for 68060 which otherwise traps and emulates 64-bit muls.l
  44.  
  45. @FixedMul_060fpu
  46.         fmove.l    d0,fp0
  47.         fmul.l    d1,fp0
  48.         fmul.s    #0.000015258789,fp0    ; d0 * d1 / 65536 (* reciprocal)
  49.         fmove.l    fp0,d0
  50.         rts
  51.  
  52. ;-----------------------------------------------------------------------
  53.         cnop    0,4
  54.  
  55. ; I'm told all Amiga 68060 accelerators have FPUs, but just in case...
  56.  
  57. @FixedMul_060    movem.l d2-d5,-(sp)
  58.  
  59.         clr.b    d5          ; clear sign tag
  60.         tst.l    d0          ; multiplier negative?
  61.         bge    .not1
  62.         neg.l    d0
  63.         or.b    #1,d5
  64. .not1
  65.         tst.l    d1          ; multiplicand negative?
  66.         bge    .not2
  67.         neg.l    d1
  68.         eor.b    #1,d5
  69. .not2
  70.         move.l    d0,d2       ; mr
  71.         move.l    d0,d3       ; mr
  72.         move.l    d1,d4       ; md
  73.         swap    d3          ; hi_mr in lo d3
  74.         swap    d4          ; hi_md in lo d4
  75.  
  76.         mulu.w    d1,d0       ; [1] lo_mr * lo_md
  77.         mulu.w    d3,d1       ; [2] hi_mr * lo_md
  78.         mulu.w    d4,d2       ; [3] lo_mr * hi_md
  79.         mulu.w    d4,d3       ; [4] hi_mr * hi_md
  80.  
  81.         clr.l    d4
  82.         swap    d0
  83.         add.w    d1,d0
  84.         addx.l    d4,d3
  85.         add.w    d2,d0
  86.         addx.l    d4,d3
  87.         swap    d0
  88.  
  89.         clr.w    d1
  90.         clr.w    d2
  91.  
  92.         swap    d1
  93.         swap    d2
  94.         add.l    d2,d1
  95.         add.l    d3,d1
  96.  
  97.         tst.b    d5          ; check sign of result
  98.         beq    .skip
  99.  
  100.         not.l    d0
  101.         not.l    d1
  102.         addq.l    #1,d0
  103.         addx.l    d4,d1
  104.  
  105. .skip
  106.         move.w    d1,d0
  107.         swap    d0
  108.  
  109.         movem.l    (sp)+,d2-d5
  110.         rts
  111.  
  112. ;-----------------------------------------------------------------------
  113.         cnop    0,4
  114.  
  115. ; fixed_t FixedDiv (fixed_t a, fixed_t b)
  116.  
  117. @FixedDiv_040    movem.l    d2/d3,-(sp)
  118.         move.l    d0,d3
  119.         swap    d0
  120.         move.w    d0,d2
  121.         ext.l    d2
  122.         clr.w    d0
  123.         tst.l    d1
  124.         beq.b    3$        ; check for divide by 0 !
  125.         divs.l    d1,d2:d0
  126.         bvc.b    1$
  127. 3$        eor.l    d1,d3
  128.         bmi.b    2$
  129.         move.l    #$7fffffff,d0
  130.         bra.b    1$
  131. 2$        move.l    #$80000000,d0
  132. 1$        movem.l    (sp)+,d2/d3
  133.         rts
  134.  
  135. ;-----------------------------------------------------------------------
  136.         cnop    0,4
  137.  
  138. ; m68060fpu fixed division
  139.  
  140. @FixedDiv_060fpu
  141.         tst.l    d1
  142.         beq.b    3$        ; check for divide by 0 !
  143.         fmove.l    d0,fp0
  144.         fmove.l    d1,fp1
  145.         fdiv.x    fp1,fp0
  146.         fmul.s    #65536.0,fp0
  147.         fmove.l    fp0,d0
  148.         rts
  149.  
  150. 3$        eor.l    d1,d0
  151.         bmi.b    2$
  152.         move.l    #$7fffffff,d0
  153.         rts
  154.  
  155. 2$        move.l    #$80000000,d0
  156.         rts
  157.  
  158. ;-----------------------------------------------------------------------
  159.         section    __MERGED,bss
  160.  
  161. ; pointers to CPU-specific FixedMul and FixedDiv routine
  162.  
  163. _FixedMul    ds.l    1
  164. _FixedDiv    ds.l    1
  165.  
  166. ;-----------------------------------------------------------------------
  167.         end
  168.